﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_Placard_Add : OTS.AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.TestPurview(HttpContext.Current, OTS.enumSysRight.Placard);
        if (!Page.IsPostBack)
        {

            DoPageBind();

        }
    }
    private void DoPageBind()
    {
        string _pid = Request.QueryString["pid"];
        if (null != _pid && !"".Equals(_pid) && OTS.Common.Help.IsNumber(_pid)) //编辑
        {
            this.txtID.Text = _pid;
            OTS.BLL.PlacardBLL bll = new OTS.BLL.PlacardBLL();
            OTS.Model.placard model = bll.GetModel(int.Parse(_pid));
            if (model != null)
            {
                this.txtExpiryTime.Text = model.plaExpiryTime ;
                this.txtTime.Text =  model.plaTime ; 
                
                this.txtTitle.Text = model.plaTitle;
                this.txtURL.Text = model.plaURL;
                this.edit_content.Text = model.plaContent;
                this.ddlType.SelectedValue = model.plaType.ToString();
            }
        }
        else
        {
            this.txtID.Text = "0";
            this.txtTime.Text = OTS.Common.Help.GetCurrentDate();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        OTS.Model.placard model = new OTS.Model.placard();
        OTS.BLL.PlacardBLL bll = new OTS.BLL.PlacardBLL();

        model.plaExpiryTime = this.txtExpiryTime.Text;
        model.plaTitle = this.txtTitle.Text;
        model.plaURL = this.txtURL.Text;
        model.plaContent = this.edit_content.Text;
        model.plaType = int.Parse(this.ddlType.SelectedValue);
        if (this.txtID.Text == "0" || this.txtID.Text == "") //增加
        {
            OTS.Model.SessionUser sUser= this.getSessionUser(HttpContext.Current);
            model.plaUID = sUser.uid;
            if (bll.Add(model))
                Response.Redirect("Placard.aspx");
            else
                OTS.Common.Jscript.Alert("增加失败！");
        }
        else //修改
        {
            model.plaID = int.Parse(this.txtID.Text);
            if (bll.Update(model))
                Response.Redirect("Placard.aspx");
            else
                OTS.Common.Jscript.Alert("更新失败！");
        }

    }
}
